<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 */
class Ocpc360Search extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'ocpc_360_search';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];


    /**
     * 根据qhclickid查询是否存在
     * @param string $qhclickid
     * @return bool
     */
    public static function existsQhclickid(string $qhclickid): bool
    {
        if (empty($qhclickid)) {
            return false;
        }

        return self::where('qhclickid', $qhclickid)
//            ->where('channel_id', $channel)
            ->exists();
    }

    /**
     * @param array $params
     * @return int
     */
    public static function addLog(array $params = []): int
    {
        $data = [
            'qhclickid'      => $params['qhclickid'] ?? '',
            'flag'        => 1,
            'created_at'  => date('Y-m-d H:i:s'),
            'updated_at'  => date('Y-m-d H:i:s')
        ];

        return self::insertGetId($data);
    }

    static function getData()
    {
        $data= self::where('flag',1)->first();

        if (empty($data))
        {
            return false;
        }

        return $data;
    }
}